using System.Collections;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Basmus.Tests
{
    public static class SequenceAssert
    {
        private static ICollection ToCollection(this IEnumerable seq)
        {
            var list = new ArrayList();
            foreach (var i in seq)
            {
                list.Add(i);
            }
            return list;
        }

        public static void AreEqual(IEnumerable expected, IEnumerable actual, string message)
        {
            if (expected == null)
            {
                Assert.IsNull(actual, message);
            }
            else
            {
                Assert.IsNotNull(actual, message);
                CollectionAssert.AreEqual(expected.ToCollection(), actual.ToCollection(), message);
            }
        }

        public static void AreEqual(IEnumerable expected, IEnumerable actual)
        {
            AreEqual(expected, actual, null);
        }

        public static void AreEquivalent(IEnumerable expected, IEnumerable actual, string message)
        {
            if (expected == null)
            {
                Assert.IsNull(actual, message);
            }
            else
            {
                Assert.IsNotNull(actual, message);
                CollectionAssert.AreEquivalent(expected.ToCollection(), actual.ToCollection(), message);
            }
        }
    }
}